package com.megoc.menu.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.megoc.menu.R;
import com.megoc.menu.model.collect.ListRecommed;

import java.util.List;

/**
 * Created by Megoc on 2015/10/15.
 */
public class MenuReadListAdapter extends BaseAdapter{

    private List<ListRecommed> listRecommeds;
    private Context context;

    public MenuReadListAdapter(List<ListRecommed> listRecommeds, Context context) {
        this.listRecommeds = listRecommeds;
        this.context = context;
    }

    @Override
    public int getCount() {
        return listRecommeds.size();
    }

    @Override
    public Object getItem(int position) {
        return listRecommeds.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHolder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_menu_read_listview,null);
            viewHolder=new ViewHolder();
            viewHolder.simpleDraweeView= (SimpleDraweeView) convertView.findViewById(R.id.read_listview_img);
            viewHolder.titleView= (TextView) convertView.findViewById(R.id.read_listview_title);
            viewHolder.detailView= (TextView) convertView.findViewById(R.id.read_listview_detail);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        ListRecommed listRecommed=listRecommeds.get(position);
        Uri uri=Uri.parse(listRecommed.getImg());
        viewHolder.simpleDraweeView.setImageURI(uri);
        viewHolder.titleView.setText(listRecommed.getTitle());
        viewHolder.detailView.setText(listRecommed.getIntro());
        return convertView;
    }
    class ViewHolder{
        SimpleDraweeView simpleDraweeView;
        TextView titleView;
        TextView detailView;
    }
}
